<?php
if (!defined('CURRENT_PATH')){
	die('Hacking attempt');
	}	
if($_REQUEST['act']&&$_REQUEST['act']=='del'){
	if(isset($_REQUEST['id'])){
		$id=intval($_REQUEST['id']);
		if(in_array($id,array('1','2','3','4','5'))){
			$this->error('此分类不能删除！','');	
		}
		$ct=spClass("category");
		$ct->delete($conditions=array('id'=>$id));		
	
	$this->success('分类删除成功！','');	
	}else{
		$this->error(':( oops !');
	}
}else if($_REQUEST['act']&&$_REQUEST['act']=='save'){	
		$pid=isset($_REQUEST['id'])&&in_array(intval($_REQUEST['id']),array('1','2','3','4','5'))?intval($_REQUEST['id']):die(':( oops !');
		$ct=spClass("category");
		$ct->create($row=array('id'=>null,'pid'=>$pid,'sid'=>$this->spArgs('showorder'),'datil'=>$this->spArgs('name'),));		
	    $this->success('分类添加成功！','');	
			
}else if($_REQUEST['act']&&$_REQUEST['act']=='save2'){
	$id=isset($_REQUEST['id'])?intval($_REQUEST['id']):die("请指定参数");
	$showOrder=$this->spArgs(showorder);
	$showOrder=$showOrder>=0?$showOrder:0;
	$showOrder=$showOrder<=9999?$showOrder:9999;
	$ct=spClass("category");
	$ct->update($row=array('id'=>$id),$newrow=array('sid'=>$showOrder,'datil'=>$this->spArgs(name)));	
	$this->success('修改成功！','');	
			
}else if($_REQUEST['act']&&($_REQUEST['act']=='addchild'||$_REQUEST['act']=='modify')){
	if($_REQUEST['act']=='addchild'){
		$this->button='添加';
			$id=isset($_REQUEST['id'])?intval($_REQUEST['id']):0;
			$this->action='/index.php?c=admin&a=sysconfig&mod=classadd&act=save&id='.$id;
	}else{
		$id=isset($_REQUEST['id'])?intval($_REQUEST['id']):die("请指定参数");		
		$this->button='保存';
		$this->action='/index.php?c=admin&a=sysconfig&mod=classadd&act=save2&id='.$id;
		$ct=spClass("category");
		$this->res=$ct->find($condition=array('id'=>$id));		
	}
	$this->display('management/classify_add.html');
}else{
/**-目录结构1--------------**/	
		import(APP_PATH.'/controller/lib/category.php');
		$ct=spClass("category");
		$result=$ct->findAll('','sid desc');
		$constructSm=new Tree($result);//construct sub menu
		$this->arr1=$constructSm->leaf();

	
$this->display('management/classify_list.html');	
		
}	